package com.zzty.zzlp.dao;

import com.zzty.zzlp.entity.TeamExam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface TeamExamMapper {
    @Insert("insert into teamexam (id,date,questions,clazzId) values (#{id},#{date},#{questions},#{clazzId})")
    public void addTeamExam(TeamExam te);

    @Update("update teamexam set winnerId1=#{winnerId1} , winnerId2=#{winnerId2} where id=#{id}")
    public void updateWinnerIds(TeamExam teamExam);

    @Select("select * from teamexam where date=#{date} and clazzId=#{clazzId}")
    public TeamExam getInfoByDateAndClazzId(@Param("date") String date, @Param("clazzId") Integer clazzId);

    @Select("select max(id) from teamexam")
    public Integer getNextId();

    @Select("select * from teamexam where clazzId=#{clazzId} order by date desc limit #{page},5")
    public List<TeamExam> searchTeamExamByClazzId(@Param("clazzId") Integer clazzId, @Param("page") Integer page);

    @Select("select * from teamexam where clazzId=#{clazzId}")
    public List<TeamExam> searchTeamExamOnlyByClazzId(@Param("clazzId") Integer clazzId);

    @Insert("INSERT INTO teamexam (date,questions,clazzId) VALUES (#{date},#{questions},#{clazzId});SELECT @@Identity")
    public Integer searchNewId(@Param("date") String date, @Param("questions") String questions,
                               @Param("clazzId") Integer clazzId);

    @Select("select *  from selfexam where clazzId=#{clazzId} and winnerId is null")
    public List<TeamExam> searchTeamExamByWinnerIdAndClazzId(@Param("clazzId") Integer clazzId);

    @Select("select * from teamexam where clazzId=#{clazzId} order by date  limit #{page},10")
    public List<TeamExam> searchTenTeamExamByClazzId(@Param("clazzId") Integer clazzId, @Param("page") Integer page);

}
